var dateFormat = require('dateformat');

/**
 * 存储localStorage
 */
export const setStore = (name, content) => {
    if (!name) return;
    if (typeof content !== 'string') {
        content = JSON.stringify(content);
    }
    window.localStorage.setItem(name, content);
}

/**
 * 获取localStorage
 */
export const getStore = name => {
    if (!name) return;
    return window.localStorage.getItem(name);
}

/**
 * 删除localStorage
 */
export const removeStore = name => {
    if (!name) return;
    window.localStorage.removeItem(name);
}


/**
 *
 * @param strTime 20190226162436
 * @returns {string}
 */
export const utilFormatStrTime = strTime => {
    if (!strTime) return "";
    // console.log(strTime)
    // console.log(new Date(strTime))
    // let d = new Date(strTime.substring(0, 4), strTime.substring(4, 6), strTime.substring(6, 8), strTime.substring(8, 10), strTime.substring(10, 12), strTime.substring(12, 14))
    // console.log(d)
    // return dateFormat(d, 'yyyy-MM-dd hh:mm:ss')
    return strTime.substring(0, 4) + "-" + strTime.substring(4, 6) + "-" + strTime.substring(6, 8) + " " + strTime.substring(8, 10) + ":" + strTime.substring(10, 12) + ":" + strTime.substring(12, 14)
}

/***
 *
 * @param strMoney 1222
 * @returns {string} ￥12.22元
 */
export const utilFormatMoneyFen2Yuan = strMoney => {
    if (!strMoney) return "￥0元";
    // console.log(strMoney)
    // console.log(new Date(strTime))
    // let d = new Date(strTime.substring(0, 4), strTime.substring(4, 6), strTime.substring(6, 8), strTime.substring(8, 10), strTime.substring(10, 12), strTime.substring(12, 14))
    // console.log(d)
    // return dateFormat(d, 'yyyy-MM-dd hh:mm:ss')
    return "￥" + strMoney.substring(0, strMoney.length - 2) + "." + strMoney.substring(strMoney.length - 2) + "元"
}


export const str2Number = str => {
    if (!str || str == "") return 0;
    // console.log(str)
    return Number(str)
}
